package com.yh.autobio.fragment;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.print.PrintJob;
import android.print.PrintManager;
import android.support.design.widget.Snackbar;
import android.support.v4.print.PrintHelper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.Button;

import com.google.gson.Gson;
import com.yh.autobio.AppConfig;
import com.yh.autobio.AppContext;
import com.yh.autobio.R;
import com.yh.autobio.api.RetrofitSingleton;
import com.yh.autobio.base.BaseFragment;
import com.yh.autobio.base.BaseListFragment;
import com.yh.autobio.common.StringUtils;
import com.yh.autobio.common.TDevice;
import com.yh.autobio.common.UIHelper;
import com.yh.autobio.modules.adatper.ListBaseAdapter;
import com.yh.autobio.modules.adatper.MyPrintPdfAdapter;
import com.yh.autobio.modules.adatper.PackingListAdapter;
import com.yh.autobio.modules.bean.CM;
import com.yh.autobio.modules.bean.InvoiceBean;
import com.yh.autobio.modules.bean.InvoiceBody;
import com.yh.autobio.modules.bean.InvoiceHead;
import com.yh.autobio.modules.bean.InvoiceSubBean;
import com.yh.autobio.modules.bean.MatSubBean;
import com.yh.autobio.modules.bean.PackingBean;
import com.yh.autobio.modules.bean.ProductBean;
import com.yh.autobio.modules.bean.SimpleBackPage;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by john on 2018/3/9 0009. 09:37
 */

public class PackingListFragment extends BaseListFragment<PackingBean> {

    String mVal="";
    @Override
    protected ListBaseAdapter<PackingBean> getListAdapter() {
        return new PackingListAdapter(mActivity);
    }
    @Override
    public void inputAction(String str) {
        super.inputAction(str);
        showWaitDialog();
        mCurrentPage = 1;
        mAdapter.clear ();
//        if (!StringUtils.isEmpty(str)){
//            mVal=str;
//        }else {
//            mVal="";
//        }
        sendRequestData(null);
    }
    @Override
    public void initView(View view) {
        super.initView(view);
        img_shaixuan.setVisibility(View.GONE);
        iv_search.setOnClickListener(this);
        leftDate = new String[]{"收货单位或单据编号"};
        et_earch.setHint(leftDate[0] + "模糊查询");
    }
    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.iv_search:
                TDevice.hideSoftKeyboard(mActivity);
                sendRequestData(null);
                break;
        }
    }
    @Override
    protected void sendRequestData(String id) {
        super.sendRequestData(id);
        showWaitDialog();
        String s = et_earch.getText().toString();
        if (!StringUtils.isEmpty(s)){
            mVal=s;
        }else {
            mVal="";
        }
        RetrofitSingleton.getApiService(mActivity).
                StockPacking(mVal,mCurrentPage, AppContext.PAGE_SIZE)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        super.onItemClick(parent, view, position, id);
        PackingBean item = mAdapter.getItem(position);
        if (item != null) {
            Bundle bundle = new Bundle();
            bundle.putString("ID",item.getId());
            bundle.putSerializable("HEAD",item);
            UIHelper.showSimpleBack(mActivity, SimpleBackPage.PACKINGDETAIL, bundle, "装箱单详情");
        }
    }
}
